import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userinfo: {}
  },
  getters: {
    nickname: state => state.userinfo.nickname
  },
  mutations: {

    // ,保存token
    updateToken (state, newToken) {
      state.token = newToken
    },
    // 保存用户信息
    updateUserInfo (state, info) {
      state.userinfo = info
    }
  },
  actions: {

  },
  modules: {
  },
  plugins: [
    createPersistedState() // 注入持久化插件
  ]
})
